<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>scroll事件案例</title>
    <style>
        /* 必须加上此css样式，js才能获取到clientHeight */
        html,
        body {
            width: 100%;
            height: 100%;
        }
    </style>
    <script>
        function scrollChange() {
            srpos = document.getElementById('srpos')
            srpos.innerText = '滚动条滚动到：' + document.documentElement.scrollTop;
            // 使srpos 不随滚动条滚动，始终固定在同一位置
            srpos.style.top = document.documentElement.scrolTop + "px"
        }
    </script>
</head>

<body onscroll="scrollChange()">
    <!-- 让div高度为了300%  ，产生滚动条-->
    <div style="height: 300%;"><br>
        <font id="srpos" style="position: relative;top:0px">滚动条滚动到0px</font>
    </div>
</body>

</html>